package com.lg.startertemplate.povo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;

import java.util.List;

@Data
@Slf4j
public class PageResult<T>  {
    private long totalData;
    private int currentCount;
    private int currentPage;


    private List<T> data;

    public static PageResult formatByPageDate(Page page){
        PageResult result = new PageResult<>();
        try {

            result.setCurrentCount(page.getTotalPages());
            result.setCurrentPage(page.getNumber()+1);

            result.setTotalData(page.getTotalElements());
            result.setData(page.getContent());
        } catch (Exception e) {
            log.error("数据格式化出错",e);
        }

        return result;
    }

}
